package com.onpositive.funkytable.test;

import java.text.DateFormat;
import java.util.Date;

import com.onpositive.data.IPropertyMetadata;
import com.onpositive.funkytable.model.IModelElement;


public class PropertyValue implements IModelElement{

	protected IPropertyMetadata property;
	protected Object value;
	protected boolean needsLabel=true;
	

	public PropertyValue(IPropertyMetadata property, Object value) {
		super();
		this.property = property;
		this.value = value;
	}


	@Override
	public String title() {
		return property.id()+": ";
	}
	
	


	@Override
	public Object value() {
		if (value instanceof ValueSequence){
			ValueSequence dw=(ValueSequence) value;
			StringBuilder bld=new StringBuilder();
			for (String s:dw.sequence){
				bld.append(s);
				bld.append(", ");
			}
			if (bld.length()>0){
				bld.deleteCharAt(bld.length()-2);
			}
			return bld.toString();
		}
		if (value instanceof Date){
			return DateFormat.getDateInstance().format(value);
		}
		if (value instanceof Object[]){
			Object[]vv=(Object[]) value;
			return UnitFormatter.format((Double)vv[1], vv[0].toString());
		}
		return value;
	}


	@Override
	public boolean needsLabel() {
		return needsLabel;
	}
	
}
